<?php

class ChangeForm extends sfGuardUserForm {

    public function configure() {
        // removemos todos los widgets que no queremos mostrar
        unset(
                $this['is_active'],
                $this['is_super_admin'],
                $this['updated_at'],
                $this['groups_list'],
                $this['permissions_list'],
                $this['last_login'],
                $this['created_at'],
                $this['salt'],
                $this['algorithm']
                //$this['first_name'],
                //$this['last_name'],
                //$this['email_address'],
                //$this['telefono'],
        );

        // orden
        $this->widgetSchema->setPositions(array('id','username','first_name','last_name','email_address','password'));

        // Colocamos el password validation y el password de confirmación.

        $this->widgetSchema['username'] = new sfWidgetFormInputHidden();
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
        $this->validatorSchema['password']->setOption('required', false);
        $this->validatorSchema['password']->setOption('min_length', 6);
        $this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
        $this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password'];

        $this->validatorSchema['password']->setMessage('required', 'Ingrese su Password');
        $this->validatorSchema['password']->setMessage('min_length', 'El largo mínimo del password es de 6 caracteres.');
        $this->validatorSchema['password_confirmation']->setMessage('required', 'Ingrese su Password');
        $this->validatorSchema['password_confirmation']->setMessage('min_length', 'El largo mínimo del password es de 6 caracteres.');

        $this->widgetSchema->setLabels(array(
            'first_name' => 'Nombre',
            'last_name' => 'Apellido',
            'password' => 'Nuevo Password',
            'password_confirmation' => 'Repetir Password',
            'email_address' => 'Email'
        ));

        $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_confirmation', array(), array('invalid' => 'The two passwords must be the same.')));

        $this->widgetSchema['first_name']->setAttributes(array("class"=>"box"));
        $this->widgetSchema['last_name']->setAttributes(array("class"=>"box"));
        $this->widgetSchema['email_address']->setAttributes(array("class"=>"box"));
        $this->widgetSchema['password']->setAttributes(array("class"=>"box"));
        $this->widgetSchema['password_confirmation']->setAttributes(array("class"=>"box"));

    }

}
